﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FMixPlayer
{
    public partial class FormDiagram : Form
    {
        public FormDiagram(Task inputTask)
        {
            InitializeComponent();

            exg2antt1.BeginUpdate();
            exg2antt1.ReadOnly = exontrol.EXG2ANTTLib.ReadOnlyEnum.exReadOnly;
            exg2antt1.LinesAtRoot = exontrol.EXG2ANTTLib.LinesAtRootEnum.exLinesAtRoot;
            exg2antt1.ScrollBySingleLine = true;
            exg2antt1.MarkSearchColumn = false;
            exg2antt1.Columns.Add("Задача");
            exg2antt1.Columns.Add("Исполнитель").HeaderBold = true;

            exontrol.EXG2ANTTLib.Chart chart = exg2antt1.Chart;
            chart.AllowCreateBar = exontrol.EXG2ANTTLib.CreateBarEnum.exNoCreateBar;
            chart.FirstVisibleDate = new DateTime(2012, 1, 1);
            chart.PaneWidthLeft = 196;
            chart.LevelCount = 2;

            exontrol.EXG2ANTTLib.Bars bars = chart.Bars;
            bars.Copy("Task", "RTask").Color = Color.Red;
            bars.Add("Task%Progress").Shortcut = "Percent";
            bars.Add("Task:Split").Shortcut = "TSplit";

            exontrol.EXG2ANTTLib.Bar bar = bars.Add("Task%Progress:Split");
            bar.Shortcut = "TPercent";
            bar.Height = 16;

            // The gBFLBCJwB... string was defined by dragging the "task1.ebn" file to eximages tool
            exg2antt1.VisualAppearance.Add(0x23, "gBFLBCJwBAEHhEJAEGg4BG4Cg6AADACAxRDAMgBQKAAzQFAYahmGQBIRGcZYJhUAIIRZGMIjFDcEwxC6NIpAWLoJDCH4mSTHYygJIMWwzDiBZgkCA4fiGDIzABKEBzUAAbxPGqNKAjEB4JiONIJi7feiwAotf4WT7Kl5pHomLYfAjGQL0LIkBytJymaYiWZxSDUJZkWZNYyjBY8EzXNqXI7oSKaZgORouXhUM53VLtbzxFqZJijegoWjefI8T5UVwxUA0EzmAAGa5ACr6MqCFaHR7VEi1NINMQTRqBazgPIaHp6CZgZZCNoXAAFS5ZN61LYmfLcOx+CZ1ZBfd44VLMP4TPbdYxufD9AzrNLAchCVS8CAGcTvUQAOJ4aKdL4rG6WR1nWERajWSo5AOXB0jofBwAAIgSFANIYk6BxTpgYwfFMUhIESX4EGQbQJBQQh6BoSQAGILBwGcHBlDoAhSk0YxwlyARNkMQJPDOIIoDIC4DGCCAiAOBJUnUKRLDYDoTjICIDGGSA+B6A4iAgdJOgYDpIE2J4BCAaIIj8KYJHIdB2BiSIxgwTQjAWYJ+DQD5jBENguBiSwigiDoDGIZAOBuApMBkFg7g6S4CGwfg1AsIhsmwLZJhkPhRhQIo4jYL4OmQBYIACAgLGMCJFhIJIpEoYoUCYOROGaFIkhGeIUBuRY4CECYDGaEosH4FZmFmVhkh2Zh5mIaYPEiaY+AuDhkkkOh4h2J4aBYUogGPVYIg2aBKDaA4jmYaJegqAYoAkNoOiGKQKB4TYiGEY5+HyGhOlMDIqigag6gqJIpmoaomiWKpnkmcgnD+YIJgAfoqCqOpSjaKImhibhuicVJqkYV4LmUWoQncMpLGsDI2ikKAZB4L4EiWKBSAMNRMEKXhpg4Yx4l4OYaEwMpgi2CQkBAAQBICA=");
            //exg2antt1.VisualAppearance.Add(1, "D:\Exontrol\ExG2antt.NET\sample\EBN\task1.ebn")
            bars.Add("Skin").Color32 = 0x23000000;

            bar = bars.Copy("Task", "NewBar");
            bar.EndShape = exontrol.EXG2ANTTLib.ShapeCornerEnum.exShapeIconCircle;
            bar.EndColor = Color.Red;

            exontrol.EXG2ANTTLib.Items items = exg2antt1.Items;

            int i;


            for (int a = 0; a <= FormMain.Tasks.Count - 1; a++)
            {
                i = items.AddItem(FormMain.Tasks[a].name);
                items.set_CellValue(i, 1, FormMain.Tasks[a].executor);
                items.AddBar(i, "Percent", Convert.ToDateTime(FormMain.Tasks[a].starttime), Convert.ToDateTime(FormMain.Tasks[a].endtime), "B");
                float percents =  (float)FormMain.Tasks[a].completed / 100;
                items.set_ItemBar(i, "B", exontrol.EXG2ANTTLib.ItemBarPropertyEnum.exBarPercent, percents);
                items.set_ItemBar(i, "B", exontrol.EXG2ANTTLib.ItemBarPropertyEnum.exBarShowPercentCaption, true);
                items.set_BarCanMove(i, "B", false);
                items.set_BarCanResize(i, "B", false);
                
                if(FormMain.Tasks[a].status!="completed")items.set_BarColor(i,"B",Color.PaleGreen);
                items.set_ItemBar(i, "B", exontrol.EXG2ANTTLib.ItemBarPropertyEnum.exBarToolTip, "Назначена:\n" + FormMain.Tasks[a].executor+" "+ FormMain.Tasks[a].comment);
            }
            items.set_LockedItemCount(exontrol.EXG2ANTTLib.VAlignmentEnum.exBottom, 1);
            i = items.get_LockedItem(exontrol.EXG2ANTTLib.VAlignmentEnum.exBottom, 0);
            items.set_ItemDivider(i, 0);
            items.set_ItemDividerLineAlignment(i, exontrol.EXG2ANTTLib.DividerAlignmentEnum.DividerTop);
            items.set_CellValue(i, 0, "And remember you have more options for bars....");
            items.set_CellSingleLine(i, 0, false);
            exg2antt1.EndUpdate();

            //exprint1.ToolBarFormat += ",|,200";

        }


        internal DateTime DateFromString(string s)
        {
            string delimStr = "//";
            char[] delimiter = delimStr.ToCharArray();
            string[] sA = s.Split(delimiter);
            return new DateTime(int.Parse(sA[2]), int.Parse(sA[0]), int.Parse(sA[1]));
        }

    }
}
